<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="/">

<fo:root>

	<!-- Layout della pagina -->
	<fo:layout-master-set>
		<fo:simple-page-master master-name="layout" margin-bottom="10mm" margin-left="10mm" margin-top="10mm" margin-right="10mm" page-height="297mm" page-width="210mm">
		<xsl:choose>
				<xsl:when test="/dati/scheda"><xsl:apply-templates select="/dati/scheda" mode="dim-scheda"/></xsl:when>
				<xsl:otherwise><xsl:call-template name="dim-standard" /></xsl:otherwise>
			</xsl:choose>
			<fo:region-before margin-top="5mm"></fo:region-before>
			<fo:region-after extent="5mm" margin-bottom="5mm" margin-right="5mm" margin-left="5mm"></fo:region-after>
		</fo:simple-page-master>
	</fo:layout-master-set>
	<!-- Fine Layout della pagina -->
	
	
	<fo:page-sequence master-reference="layout">
	<!-- Contenut statico della pagina -->
		<fo:static-content flow-name="xsl-region-before">
			<fo:block-container xsl:use-attribute-sets="border-style" border-width="2mm" height="60mm" width="190mm" top="2mm" padding=".6mm" position="absolute">
				<xsl:call-template name="logo"><xsl:with-param name="image"><xsl:value-of select="/dati/speciali/logo/img/@src"></xsl:value-of></xsl:with-param></xsl:call-template>
				<fo:block text-align="end" font-style="oblique">by Power Chiosco</fo:block>
			</fo:block-container>
				<xsl:apply-templates select="/dati/scheda" mode="title-scheda"></xsl:apply-templates>
				<xsl:apply-templates select="/dati/response" mode="back-response"></xsl:apply-templates>
				<xsl:apply-templates select="/dati/errore" mode="back-errore"></xsl:apply-templates>
			
	</fo:static-content>
		<fo:static-content flow-name="xsl-region-after">
			<fo:table table-layout="fixed" width="190mm">
				<fo:table-column column-width="160mm"></fo:table-column>
				<fo:table-column column-width="30mm"></fo:table-column>
				<fo:table-body>
					<fo:table-row>
						<fo:table-cell>
							<fo:block><xsl:apply-templates select="/dati/speciali/info-pagina"></xsl:apply-templates></fo:block>
						</fo:table-cell>
						<fo:table-cell>
							<fo:block xsl:use-attribute-sets="page">Page<fo:page-number></fo:page-number></fo:block>
						</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
			</fo:table>
		</fo:static-content>
		<!-- Fine contenuto statico della pagina -->		
		
		
		<!-- Contenuto dinamico -->
		<fo:flow flow-name="xsl-region-body">
			<xsl:apply-templates select="/dati/speciali/messaggio"></xsl:apply-templates>
			<xsl:apply-templates select="/dati/scheda" mode="body-scheda"></xsl:apply-templates>
			<xsl:apply-templates select="/dati/response" mode="body-response"></xsl:apply-templates>
			<xsl:apply-templates select="/dati/errore" mode="body-errore"></xsl:apply-templates>
				
		</fo:flow>
		<!-- Fine Contenuto dinamico -->

		</fo:page-sequence>
	</fo:root>
</xsl:template>

<!-- Template per gli elementi speciali -->

	<xsl:template match="/dati/speciali/info-pagina">
		<fo:inline text-align="left"><xsl:apply-templates select="*|text()"></xsl:apply-templates></fo:inline>
	</xsl:template>

<xsl:param name="imgdef" select="'http://ltw0807.web.cs.unibo.it/df/pdf/img/slide-tigelle.jpg'"></xsl:param>

	<xsl:template name="logo">
		<xsl:param name="image"></xsl:param>	
		<xsl:choose>
			<xsl:when test="$image=''">
				<fo:block text-align="center"><fo:external-graphic src="url('{$imgdef}')" content-height="140px" content-width="525px"></fo:external-graphic></fo:block>
			</xsl:when>
			<xsl:otherwise>
			<fo:block text-align="center"><fo:external-graphic src="url('{$image}')" content-height="140px" content-width="525px"></fo:external-graphic></fo:block>
	
			</xsl:otherwise>
		</xsl:choose>
		</xsl:template>

<!--<xsl:template name="messaggio">-->
	<xsl:template match="/dati/speciali/messaggio">
		<fo:block-container xsl:use-attribute-sets="layout-style">
			<fo:block-container xsl:use-attribute-sets="normal-text">
				<fo:block><xsl:apply-templates select="*|text()"></xsl:apply-templates></fo:block>
			</fo:block-container>
		</fo:block-container>
	</xsl:template>

<!-- Fine Template per gli elementi speciali -->

</xsl:stylesheet>
